home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------
- EWFEXT.C -- Extension DLL for E! and File Manager - version 2.1
-
- To compile: nmake /f ewfext.mak
-
- Please use the version of WFEXT.H coming with the W4FW SDK.
-
- Once compiled, copy EWFEXT.DLL to any directory of your choice.
-
- This DLL is not like any other Extension DLL for E!. It's a
- standard Extension DLL for the Windows File Manager. It simply
- adds an EW item to the File Manager menu, allowing you to load
- files into E! even if no association is valid for this file.
-
- To install it, you just have to add the following line to the
- [addons] section fo WINFILE.INI:
-
- EW=c:\ew\ewfext.dll
-
- You can put this file in any directory.
-
- If E! is not running when you select the Edit item in this menu,
- it will be launched first and then the selected file(s) will be
- loaded.
-
- However, E! will not be able to load itself if the \EW directory
- has not been added to your PATH. Normally, \EW doesn't need to be
- added to your PATH but in such a case, it's mandatory. Please see
- technical note #11.
-
- --------------------------------------------------------------*/
- #include <windows.h>
-
- #define WINBALL
-
- #include <\wfwdev\include\wfext.h>
- #include "ewfext.h"
-
- /* type definition for the some API functions. */
- /* Note that we have not linked EWAPI2.LIB to this DLL. */
- /* Otherwise, E! would be systematically loaded each time */
- /* we'd try to run File Manager. */
-
- typedef void (FAR PASCAL* EWEditFileProc)(char FAR* Name);
- typedef unsigned int (FAR PASCAL* EWGetVersionProc) (void);
- typedef int (FAR PASCAL* EWMessageBoxProc) (HWND WndParent, LPCSTR Txt, LPCSTR Caption, UINT TextType);
-
- HINSTANCE hinst;
- HMENU hmenu;
- char EwApiName[11];
- HMODULE hEWLib = 0;
- EWEditFileProc EWAsynchEditFile;
- EWGetVersionProc EWGetVersion;
- EWMessageBoxProc EWMessageBox;
-
- EXT_BUTTON ewbutton[1] = {{ IDM_EDIT, 0, FMTB_BUTTON }}; // button identifier is 1
-
- int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
- LPSTR lpszCmdLine)
- {
- if (wHeapSize > 0)
- UnlockData (0) ;
- hinst = hInstance;
- lstrcpy(EwApiName, "ewapi2.dll");
- return 1 ;
- }
-
- int FAR PASCAL _export _WEP(int nParameter)
-
- {
- if (hEWLib >= 32)
- FreeLibrary(hEWLib);
- return(1);
- }
-
- HMENU FAR PASCAL _export FMExtensionProc (HWND hwnd, WORD wMsg, LONG lParam)
- {
- int count;
-
- switch (wMsg) {
- case FMEVENT_LOAD:
-
- #define lpload ((LPFMS_LOAD)lParam)
-
- /* Fill the FMS_LOAD structure. */
- lpload->dwSize = sizeof(FMS_LOAD);
- lstrcpy(lpload->szMenuName, "&EW");
-
- /* Return the handle of the menu. */
- return (DWORD) (lpload->hMenu = LoadMenu(hinst, "EWMENU"));
-
- case FMEVENT_INITMENU:
-
- hmenu = (HMENU) HIWORD(lParam);
- return (hmenu);
-
- case FMEVENT_TOOLBARLOAD:
- {
- LPFMS_TOOLBARLOAD ps;
-
- ps = (LPFMS_TOOLBARLOAD)lParam;
- ps->dwSize = sizeof(FMS_TOOLBARLOAD);
- ps->lpButtons = (LPEXT_BUTTON)ewbutton;
- ps->cButtons = 1; // two buttons to add
- ps->cBitmaps = 1; // two images in bitmap
- ps->idBitmap = IDBM_EDIT; // bitmap resource 1
- ps->hBitmap = NULL; // not a memory bitmap
- }
- break;
-
- case FMEVENT_HELPSTRING:
- {
- LPFMS_HELPSTRING ps;
-
- ps = (LPFMS_HELPSTRING)lParam;
- switch (ps->idCommand) {
- case IDM_EDIT:
- lstrcpy(ps->szHelp, "Edit File");
- break;
- }
- }
- break;
-
- case IDM_EDIT:
- {
- BOOL fLFN;
- static FMS_GETFILESEL file;
- UINT nVersion = 0;
-
- if ((hEWLib = GetModuleHandle(EwApiName)) == 0) /* EWAPI2.DLL is not loaded */
- if ((hEWLib = LoadLibrary(EwApiName)) < 32)
- /* Can't load it */
- break;
-
- EWGetVersion = (EWGetVersionProc) GetProcAddress(hEWLib, "EWGetVersion");
- EWMessageBox = (EWMessageBoxProc) GetProcAddress(hEWLib, "EWMessageBox");
-
- if (!EWGetVersion || !EWMessageBox)
- break;
-
- // Check version number
- nVersion = EWGetVersion();
- if ((HIBYTE(nVersion) < 2) || ((HIBYTE(nVersion) == 2) && (LOBYTE(nVersion) < 2)))
- {
- EWMessageBox(GetFocus(),
- "This Extension DLL needs E! version 2.02 or newer.",
- "Error!",
- MB_OK | MB_ICONEXCLAMATION);
- break;
- }
-
- count = (int) SendMessage(hwnd,
- fLFN ? FM_GETSELCOUNTLFN : FM_GETSELCOUNT,
- FMFOCUS_DIR,
- 0L);
-
-
- while (count >= 1)
- {
- /* Selection indices are zero-based (0 is first). */
- count--;
- SendMessage(hwnd,
- FM_GETFILESEL,
- count,
- (LONG) (LPFMS_GETFILESEL)&file);
- OemToAnsi(file.szName, file.szName);
-
- /* Edit File */
- /*
- A few explanations are in order here.
- When loading a file E! checks whether the file is a text file and displays
- a warning if it seems not to be the case. However, when displaying the error
- message box and if editing has been triggered from the File Manager, mouse
- and keyboard messages will not be forwarded to the dialog box. This is
- because we are currently processing a message sent to the File Manager.
- To circumvent this problem, we have added a new function to the API.
- EWAsynchEditFile doesn't wait for an error code to be returned. So,
- the messages that are sent to the application queue of E! can therefore be
- processed. Actually, EWAsynchEditFile does the same job as EWEditFile but
- the API uses PostMessage instead of SendMEssage to signal the request to E!.
-
- CAUTION: Using EWAsynchEditFile requires some special handling. Because we will
- immediately exit from FMExtensionProc, we can't allocate the "file" variable
- on the stack. Otherwise, when E! will receive the edit request from the API,
- the pointer to the filename will no longer be valid. Thus, it's mandatory to
- use a static variable to store the FMS_GETFILESEL structure.
- */
- EWAsynchEditFile = (EWEditFileProc) GetProcAddress(hEWLib, "EWAsynchEditFile");
- if (!EWAsynchEditFile)
- break;
- EWAsynchEditFile((char FAR*) file.szName);
- }
-
- break;
- }
- }
- return NULL;
- }
-